﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Media;
using Safe_Driving.TokenUser;
using DbLinq.Data.Linq;
using System.Windows;
using System.Collections;
using System.Windows.Input;

using Safe_Driving.EasyCalendar.Controler;
using Safe_Driving.EasyCalendar.Model;



namespace Safe_Driving
{
    public partial class MainWindow
    {
        #region evt buttons

        private void img_close_reserver_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Pane_Reserver_cours.Visibility = Visibility.Hidden;
        }
        
        private void btn_reserver_Click(object sender, RoutedEventArgs e)
        {
            SingletonTokenUser tok = SingletonTokenUser.GetInstance();
            AppSafeDriving dbApp = tok.DbApp;

            if ( lbl_reserver_inscrit.Content.Equals("Non") ) {
                //Inscription
                SFInSCrIt sfinscrit = new SFInSCrIt();
                sfinscrit.IDClient = tok.Client_selected.IDClient;
                sfinscrit.IDCOurs = (int)leb_reserver_id.Content;
                sfinscrit.Note = -1;

                dbApp.SFInSCrIt.InsertOnSubmit(sfinscrit);

            } else {
                //Désinscription
                SFInSCrIt d = ( from sfinscr in dbApp.SFInSCrIt
                                where    sfinscr.IDCOurs == (int)leb_reserver_id.Content 
                                        && sfinscr.IDClient == tok.Client_selected.IDClient
                                select sfinscr).SingleOrDefault();
                dbApp.SFInSCrIt.DeleteOnSubmit(d);
            }

            dbApp.SubmitChanges();

            Pane_Reserver_cours.Visibility = Visibility.Hidden;
            //this.EC_ReserverCours.jump_week(0);
        }

        #endregion

        public void manage_reservation(EventCalendar evt)
        {
            Pane_Reserver_cours.Visibility = Visibility.Visible;
            lbl_reserver_nom.Content = ((EventCal)evt.Content).Name_event;
            leb_reserver_capacite.Content = ((EventCal)evt.Content).Nb_inscrit.ToString() + " / " + ((EventCal)evt.Content).Capacite.ToString();
            leb_reserver_type.Content = ((EventCal)evt.Content).Type_session;
            leb_reserver_de.Content = evt.StartTime.ToString();
            leb_reserver_a.Content = evt.EndTime.ToString();
            leb_reserver_id.Content = ((EventCal)evt.Content).Id;

            if (((EventCal)evt.Content).Inscrit == EventCal.OuiInscrit)
            {
                lbl_reserver_inscrit.Content = "Oui";
                btn_reserver.Content = "Désinscrire";
            }
            else
            {
                lbl_reserver_inscrit.Content = "Non";
                btn_reserver.Content = "Inscrire";
            }

            
        }
    }
}
